<template>
	<view>
		<u-sticky bgColor="#fff">
			<u-tabs :list="tabs" lineColor="#fe8604" :activeStyle="{
			    color: '#333',
			    fontWeight: 'bold',
			    transform: 'scale(1.05)',
				fontSize:'30rpx'
			}" :inactiveStyle="{
			    color: '#999',
			    transform: 'scale(1)',
				fontSize:'30rpx'
			}" keyName="name" @click="tabclick"></u-tabs>
		</u-sticky>
		<view class="mainpadding2">
			<view class="flexcolumn" v-if="list.data.length==0">
				<view class="placeholderimage" style="margin-top: 200rpx;"></view>
				<view class="xiaohui margin_top main_size">暂无数据</view>
			</view>
			<view class="flexbetween flex_wrap">
				<view class="itemgoods margin_top" v-for="item in list.data" :key="item.id" @click="jumpdetail('/pages_index/shangpinxq?id=',item.id)">
					<image :src="item.image_text" class="goodsimglist" mode=""></image>
					<view class="bottompad">
						<view class="main_size hei_text yhxk">{{item.name}}</view>
						<view class="titletext xiaohuang bold margin_top2">{{item.price}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				tabsid: "",
				tabs: [{
					id: 1,
					name: '全部',
				}, {
					id: 1,
					name: '进行中',
				}, {
					id: 1,
					name: '待审核'
				}, {
					id: 1,
					name: '已完成'
				}, ],
				page: 1,
				limit: 12,
				list: {
					data: []
				},
			}
		},
		onLoad(options) {
			if(options.keywords){
				this.keywords = options.keywords
			}
			this.getfenlei()
			this.init()
		},
		methods: {
			getfenlei(){
				httpRequest.request('/api/goodscl/goodsCategory', 'GET', {
				}).then(res => {
					this.tabs = res.data
					this.tabs.unshift({
						id:0,
						name:"全部"
					})
				})
			},
			init(isPage, page) {
				let _this = this;
				let data = {
					page: page || 1,
					limit: _this.limit,
					category_id: this.tabsid,
					keywords:this.keywords
				}
				let url = '/api/goodscl/goodsIndex'
				httpRequest.request(url, 'GET', data, false, false, true).then(res => {
					this.isLoad = true
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			tabclick(e) {
				this.tabsid = e.id
				this.init()
			}
		}
	}
</script>

<style>
	.itemgoods{
		width: 48%;
		background-color: #fff;
		border-radius: 20rpx ;
	}
	.goodsimglist{
		width: 100%;
		height: 330rpx;
		border-radius: 20rpx 20rpx 0 0;
	}
	.bottompad{
		padding: 20rpx 15rpx;
	}
</style>
